<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增公司')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content ibox float-e-margins">
		<form class="form-horizontal m" id="form-post-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">公司名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyName" id="companyName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">法人姓名：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyBoss" id="companyBoss" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">负责人：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyPerson" id="companyPerson" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">密码：</label>
				<div class="col-sm-8">
					<input id="password" name="password" class="form-control" type="password">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">确认密码：</label>
				<div class="col-sm-8">
					<input id="confirm_password" name="confirm_password" class="form-control" type="password">
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">手机号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyPhone" id="companyPhone" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyEmail" id="companyEmail" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">公司链接：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="companyLink" id="companyLink" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "user/company";
	    
		$("#form-post-add").validate({
			onkeyup: false,
			rules:{
				password: {
					required: true,
					minlength: 5
				},
				confirm_password: {
					required: true,
					minlength: 5,
					equalTo: "#password"
				},
				companyName:{
					remote: {
		                url: prefix +"/checkName",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"companyName" : function() {
		                        return $.common.trim($("#companyName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				companyEmail:{
					remote: {
		                url: prefix +"/checkEmail",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"companyEmail" : function() {
		                        return $.common.trim($("#companyEmail").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				companyPhone:{
					remote: {
						url: prefix +"/checkPhone",
						type: "post",
						dataType: "json",
						data: {
							"companyPhone" : function() {
								return $.common.trim($("#companyPhone").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
				postSort:{
					digits:true
				},
			},
			messages: {
				"password": {
					required:  "请输入您的密码",
					minlength:  "密码必须5个字符以上"
				},
				"confirm_password": {
					required:  "请再次输入密码",
					minlength:  "密码必须5个字符以上",
					equalTo: "两次输入的密码不一致"
				},
		        "companyName": {
		            remote: "公司已被注册"
		        },
		        "companyEmail": {
		            remote: "请更换一个邮箱"
		        },
		        "companyPhone": {
		            remote: "请更换手机号"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/add", $('#form-post-add').serialize());
	        }
	    }
	</script>
</body>
</html>
